This project uses R to visualize data from the Institute for Health Metrics and Evaluation (IHME) Global Health Spending, 1995-2017 database. The project creates three different visualizations of the data using R.
Figure 1. Scatter Plot of Global Health Spending, 1995-2017
#file management
file1 = "/Users/adriennehall/Desktop/GEOG 456/Global Health Data/IHME_GlobalHealthFinancing_1995_2017.csv" ##this is the csv file with only global level data
df1 = read.csv(file1)
global = df1[,c(1,2,5,6)] ## recreates the data frame with only the 1, 2, 5, and 6 columns
names(global) = c("ID", "Level", "Year", "Total Spending") ## renames the column names
## Scatter Plot
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
fig1 <- plot_ly(data=global, type="scatter", x=~Year, y=~`Total Spending`,
marker = list(size = 8,
color = 'rgba(255, 182, 193, .9)',
line = list(color = 'rgba(152, 0, 0, .8)',
width = 2)))
fig1 <- fig1 %>% layout(title = 'Global Health Spending Estimates, 1995-2017',
yaxis = list(zeroline = TRUE),
xaxis = list(zeroline = FALSE))
fig1
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
Figure 2. Styled Bar Plot of Global Health Spending by Year, 1995-2017
library(RColorBrewer)
myColorPalette = brewer.pal(9,"BuGn")
myColors = colorRampPalette(myColorPalette)
count = 23 ## creates a variable with the number of years
global$Color = myColors(count)[] ## adds a column called "Colors" to the data frame, each row is assigned a color
fig2 = plot_ly(data=global, x=global$Year, y=global$`Total Spending`, name="Figure 2. Bar Plot of Global Health Spending, 1995-2017", type="bar", marker=list(color=global$Color))
fig2 = fig2 %>% layout(title = 'Global Health Spending, 1995-2017')
fig2
Figure 3. Grouped Bar Chart, Total Health Spending by World Bank Income Group, 1995-2017
#file management
main_file = "/Users/adriennehall/Desktop/GEOG 456/Global Health Data/IHME_RETROSPECTIVE_FINANCING_1995_2017_Y2020M07D09.CSV" ##this is the large original dataset
df = read.csv(main_file)
## breaking down the data into the World Bank Income Group categorizations
years = df$year[df$level=="World Bank Income Groups"]
spending = df$the_total_mean[df$level=="World Bank Income Groups"]
location = df$location_name[df$level=="World Bank Income Groups"]
## using loops to create grouped bar chart
incomeGroups = unique(location)
fig = plot_ly()
for(IG in incomeGroups){
x = years[location==IG]
y = spending[location==IG]
fig <- fig %>% add_trace(x=x,y = y, type="bar", name=IG)
}
fig
Figure 4. Styled Bar Plot with Constant Y, Global Health Spending (1995-2017)
## going back to the simple data frame (global) with only the global level figures
constY = c(rep(1,length(global$Year)))
x4 = global$Year
myColorPalette2 = brewer.pal(9, "PuBuGn")
myColors2 = colorRampPalette(myColorPalette2)
count = 23
global$Color = myColors2(count)[]
fig4 = plot_ly(global, x = x4, y = constY,marker = list(color=global$Color), name = "Bar Polar", type = "bar")
noAxisList <- list(title = "", zeroline = FALSE, showline = FALSE, showticklabels = FALSE,showgrid = FALSE)
fig4= fig4 %>% layout(title = 'Global Health Spending 1995-2017')
fig4
Data Source: Global Burden of Disease Health Financing Collaborator Network. Global Health Spending 1995-2017. Seattle, United States of America: Institute for Health Metrics and Evaluation (IHME), 2020. http://ghdx.healthdata.org/record/ihme-data/global-health-spending-1995-2017